﻿using System.Linq;
using System.Web.DomainServices;
using System.Web.DomainServices.Providers;
using System.Web.Ria;
using SoftSource.Timecard.Web.Data;

namespace SoftSource.Timecard.Web.Services
{
    [EnableClientAccess]
    [RequiresAuthentication]
    [RequiresRole("Administrator")]
    public class CategoryService : LinqToSqlDomainService<CategoryDBDataContext>
    {
        public IQueryable<Category> GetCategories()
        {            
            return this.DataContext.Categories;
        }

        public Category GetCategoryByID(int categoryID)
        {
            return this.DataContext.Categories.SingleOrDefault(category => category.CategoryID == categoryID);
        }

        public void InsertCategory(Category category)
        {
            this.DataContext.Categories.InsertOnSubmit(category);
        }

        public void UpdateCategory(Category currentCategory)
        {
            this.DataContext.Categories.Attach(currentCategory, this.ChangeSet.GetOriginal(currentCategory));
        }

        public void DeleteCategory(Category category)
        {
            this.DataContext.Categories.Attach(category);
            this.DataContext.Categories.DeleteOnSubmit(category);
        }
    }
}


